﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BCGC.BLL.Helper;
using Jalal.Library.Web;
using BCGC.BLL.MarketPlace;
using BCGC.BLL.BusinessObject.UserAccount;

public partial class submit_to_market : PublicBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!SessionManager.IsUserLoggedIn)
            {
                Response.Redirect(CustomSiteMap.Login);  
            }

            divContactInfo.Visible = false;

        }
    }

    
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Market market = new Market();
        market.Date = DateTime.Now;

        if(chkShowContactInfo.Checked)
            market.ContactInfo = Server.HtmlEncode(txtContactInfo.Text.Trim());

        market.IsActive = true;
        market.MarketContent = wucPostWriter1.Text;
        market.ShowContactInfo = chkShowContactInfo.Checked;
        market.Title =Server.HtmlEncode(txtTitle.Text.Trim());
        market.UserID = SessionManager.LoggedUser.Id;
        if (market.Save())
        {
            uccResponse.SetSuccessMessage("Your item(s) published to market and active.");
        }
        else
        {
            uccResponse.SetFailMessage("Your item(s) failed to publish into market, please try again later.");
        }
    }
    protected void chkShowContactInfo_CheckedChanged(object sender, EventArgs e)
    {
        if (chkShowContactInfo.Checked)
        {
            divContactInfo.Visible = true;
            rfvtxtContactInfo.Enabled = true;
        }
        else
        {
            divContactInfo.Visible = false;
            rfvtxtContactInfo.Enabled = false;
        }
    }
}
